﻿Imports Sistema_InformacionNaviera.BC
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL


Public Class Consultar_BillOfLading_Expo

    'Inherits System.Web.UI.Page
    Inherits PaginaBase

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


        Session("FlagBL") = 1 ' si es exportacion  

        If Not Page.IsPostBack Then
            txtNave.Text = "" : txtPto.Text = "" : txtNroBl.Text = "" : lblKvje.Text = 0
            CargarGridConsulta()

        End If
        If My.Request.Params("__EVENTTARGET") = "MiFuncionPaquetes" Then
            CargarDatosViajePopUp()
        End If



    End Sub


    Public Sub CargarDatosViajePopUp()

        If Session("BPCodViaje") = Nothing Then
            txtNave.Text = String.Empty
            txtDescripcionNave.Text = String.Empty
        Else
            txtNave.Text = Session("BPCodViaje")
            txtDescripcionNave.Text = Session("BPDesViaje")
        End If
    End Sub


    Public Sub CargarGridConsulta()
        Dim objBlImpoBE As New BillOfLadingImpoBE
        Dim lstBlImpoBE As New List(Of BillOfLadingImpoBE)
        Dim objUtil As New Funciones
        Dim objBlImpoBC As New BillOfLadingImpoBC
        objBlImpoBE.KVJE = If(txtNave.Text = String.Empty, 0, CType(txtNave.Text, Integer))
        objBlImpoBE.Ptoo = txtPto.Text.Trim
        objBlImpoBE.Nume = txtNroBl.Text.Trim
        objBlImpoBE.Bli_Flag = Session("FlagBL")

        Dim dt As DataTable = Nothing
        Dim sMensaje As String = ""

        lstBlImpoBE = objBlImpoBC.ListarBlImpo(objBlImpoBE, dt, sMensaje)
        dgBlImportacion.DataSource = lstBlImpoBE
        dgBlImportacion.DataBind()
    End Sub



    Private Sub dgBlImportacion_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles dgBlImportacion.RowCommand

        'If Val(lblKvje.Text) > 0 Then

        Dim sMensaje As String = String.Empty
        Dim bExito As Boolean
        Dim sCadenaBL As String = Convert.ToString(e.CommandArgument)
        Dim iKvje As Integer
        Dim iKbli As Integer

        iKvje = sCadenaBL.Substring(0, InStr(sCadenaBL, "|") - 1)
        iKbli = sCadenaBL.Substring(InStr(sCadenaBL, "|"), Len(sCadenaBL) - InStr(sCadenaBL, "|"))


        Session("Desglose_iKvje") = iKvje
        Session("Desglose_iKbli") = iKbli


        Select Case e.CommandName  '.ToLower
            Case "Editar"

                Session("TipoTransaccionBLImpo") = 1 ' modificar
                Session("CodigBL") = iKbli
                Session("CodigVje") = iKvje
                Response.Redirect("BillOfLadingExpo.aspx", True)

            Case "Eliminar"

                Dim objBlImpoBE As New BillOfLadingImpoBE
                objBlImpoBE.KVJE = iKvje
                objBlImpoBE.KBLM = iKbli

                Dim objPaqueteBC As New BillOfLadingImpoBC

                objPaqueteBC.EliminarBlImpo(objBlImpoBE, bExito, sMensaje)
                If bExito Then
                    Alerta("El registro fue eliminado con éxito.", False, String.Empty)
                    CargarGridConsulta()
                End If

        End Select
        'End If

    End Sub

    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        CargarGridConsulta()
    End Sub

    Protected Sub btnNuevo1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnNuevo1.Click


        'ELIMINAR TABLAS TEMPORALES 
        '----------------------------------------------------------
        Session("tbTempMercaderia") = Nothing
        Session("tbTempFlete") = Nothing
        Session("tbTempContenedor") = Nothing
        '----------------------------------------------------------
        Session("TipoTransaccionBLImpo") = 0 ' si es nuevo

        ' elelgir una nave/ viaje
        '----------------------------------------------------------------------------
        If txtNave.Text.Trim = String.Empty Then
            'MsgBox("Seleccione una nave/viaje.", True, String.Empty)
            MsgBox("Seleccione una nave/viaje.", MsgBoxStyle.Information, "")

            Exit Sub
        Else
            Session("CodNaveViajeBLImpo") = txtNave.Text.Trim
            Session("DesNaveViajeBLImpo") = txtDescripcionNave.Text.Trim

        End If

        '----------------------------------------------------------------------------
        Response.Redirect("BillOfLadingExpo.aspx", True)
        'Session("tbTempFleteTipoTransaccion") = 0 ' si es nuevo
        '----------------------------------------------------------------------------
    End Sub

    Protected Sub btnLimpiar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLimpiar.Click
        txtNave.Text = String.Empty
        txtDescripcionNave.Text = String.Empty
        txtNroBl.Text = String.Empty
        txtPto.Text = String.Empty

    End Sub

    Protected Sub dgBlImportacion_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles dgBlImportacion.SelectedIndexChanged

    End Sub

    Sub Cambiarpagina(ByVal sender As Object, ByVal e As GridViewPageEventArgs)

        Dim objBlImpoBE As New BillOfLadingImpoBE
        Dim lstBlImpoBE As New List(Of BillOfLadingImpoBE)
        Dim objUtil As New Funciones
        Dim objBlImpoBC As New BillOfLadingImpoBC
        objBlImpoBE.KVJE = If(txtNave.Text = String.Empty, 0, CType(txtNave.Text, Integer))
        objBlImpoBE.Ptoo = txtPto.Text.Trim
        objBlImpoBE.Nume = txtNroBl.Text.Trim
        objBlImpoBE.Bli_Flag = Session("FlagBL")

        Dim dt As DataTable = Nothing
        Dim sMensaje As String = ""

        lstBlImpoBE = objBlImpoBC.ListarBlImpo(objBlImpoBE, dt, sMensaje)
        dgBlImportacion.PageIndex = e.NewPageIndex
        dgBlImportacion.DataSource = lstBlImpoBE
        dgBlImportacion.DataBind()


    End Sub

End Class